﻿using PrintLabel.Tools;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 纺织贸易管理系统;

namespace PrintLabel.View
{
    public partial class ShowDefect : Form
    {
        private JuanHaoTable Roll { get; set; } = new JuanHaoTable();
        public ShowDefect(JuanHaoTable roll)
        {
            InitializeComponent();
            table3.AutoSizeColumnsMode = AntdUI.ColumnsMode.Fill;
            table3.Columns = new AntdUI.ColumnCollection()
            {
                 new AntdUI.Column ("ChiDianName","疵点名称"),
                new AntdUI.Column ("WeiZhi","位置"),
                 new AntdUI.Column ("ShuLiang","长度"),
                 new AntdUI.Column ("KouFeng","扣分"),
                  new AntdUI.Column ("IsALL","通匹"),
                   new AntdUI.Column ("EdgeDistance","边距"),
                  
            };
            Roll = roll;
        }

        private void ShowDefect_Load(object sender, EventArgs e)
        {
            if (Roll != null) 
            {
                table3.DataSource=dbContext.dbcontext.Queryable<ChiDianTable> ().Where(x=>x.JuanHao==Roll.JuanHao ).ToList ();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (table3.SelectedIndex >= 0) 
            {
                var defects=table3.DataSource as List<ChiDianTable>;
                var defect = defects[table3.SelectedIndex-1];
                if (defect != null)
                {
                    dbContext.dbcontext.Deleteable(defect).ExecuteCommand();
                    table3.DataSource = dbContext.dbcontext.Queryable<ChiDianTable>().Where(x => x.JuanHao == Roll.JuanHao).ToList();
                }
            }
            else
            {
                ShowMessage.ShowErrorMessagebox(this, "请先选择要删除的疵点");
            }
        }
    }
}
